<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>采购对账单打印</title>
    <script src="/jquery-1.8.3.min.js"></script>
    <script src="/printThis.js"></script>
    <script src="/chineseMoney.js"></script>
    <link rel="stylesheet" href="/print.css"/>
</head>
<body>
<div id="receiptPrintArea0">
    <h3 style="text-align: center"><span class="company"></span>-采购对账单</h3>
    <br/>
    <table width="100%">
        <tr>
            <td width="25%">采购日期范围：</td><td width="75%"><span class="purchaseDate"></span></td>
        </tr>
        <tr>
            <td width="25%">供应商：</td><td width="75%"><span class="supplier"></span></td>
        </tr>
        <tr>
            <td width="25%">合计金额：</td><td width="75%"><span class="total"></span></td>
        </tr>
        <tr>
            <td width="25%">大写金额：</td><td width="75%"><span class="chineseMoney"></span></td>
        </tr>
    </table>
    <br/>
    <table style="width: 100%;" class="printTable">
        <thead style="border: 1px solid">
        <td width="15%">单号</td>
        <td width="15%">采购人</td>
        <td width="15%">支付状态</td>
        <td width="15%">采购日期</td>
        <td width="15%">采购金额</td>
        <td width="25%">备注</td>
        </thead>
        <tbody id="content">
        </tbody>
    </table>
</div>
<script th:inline="javascript">
    var params = [[${params}]];
    var backAddress = params.backAddress;
    var beginPurchaseDate = params.beginPurchaseDate;
    var endPurchaseDate = params.endPurchaseDate;
    var supplierId = params.supplierId;
    var supplierName = params.supplierName;
    var companyName = params.companyName;
    function print() {
        $("#receiptPrintArea0").printThis({
            debug: false,
            importCSS: true,
            importStyle: true,
            printContainer: true,
            pageTitle: "",
            removeInline: false,
            printDelay: 333,
            header: null,
            formValues: true
        });
    }
    $.ajax({
        url: backAddress + "/api/financial/purchaseCheck",
        type: "post",
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data : JSON.stringify({
            "beginPurchaseDate" : beginPurchaseDate,
            "endPurchaseDate" : endPurchaseDate,
            "supplierId" : supplierId,
            "pageNo" : 1,
            "pageSize" : 2000
        }),
        success: function (data) {
            //console.log(data)
            $(".purchaseDate")[0].innerText = beginPurchaseDate + '至' + endPurchaseDate;
            $(".supplier")[0].innerText = supplierName;
            var str = '' ;
            var total = 0 ;
            for (var i = 0 ; i < data.data.list.length ; i++) {
                str = "<tr><td width=\"15%\">" + data.data.list[i].id + "</td>" +
                    "<td width=\"10%\">" + data.data.list[i].purchasePersonName + "</td>" +
                    "<td width=\"10%\">" + (data.data.list[i].payStatus ? '支付':'未付') + "</td>" +
                    "<td width=\"10%\">" + data.data.list[i].purchaseDate + "</td>" +
                    "<td width=\"10%\">" + data.data.list[i].amountOfMoney + "</td>" +
                    "<td width=\"45%\">" + data.data.list[i].remark + "</td></tr>" ;
                $("#content").append($(str));
                total += data.data.list[i].amountOfMoney * 100 ;
            }
            $(".total")[0].innerText = total / 100 ;
            $(".chineseMoney")[0].innerText = Arabia_to_Chinese(total / 100 + '') ;
            $(".company")[0].innerText = companyName;
            print()
        },
        error: function (status) {
            alert(status)
        }
    })
</script>
</body>
</html>